package avicit.bdp.dcs.plugin.oss;

import avicit.bdp.dcs.plugin.BaseDataxParam;
import avicit.bdp.dcs.plugin.DataxConstants;
import avicit.bdp.dcs.plugin.DataxJsonInterface;
import avicit.bdp.dcs.plugin.oss.param.OssDataxParam;

import java.util.HashMap;
import java.util.Map;

/**
 * @金航数码科技有限责任公司
 * @作者：liyb
 * @邮箱：liyb@avic-digital.com
 * @创建时间： 2023-04-27 11:39
 * @类说明：
 * @修改记录：
 */
public class OssDataxJson implements DataxJsonInterface {

    /**
     * 获取Reader插件名称
     * @return
     */
    @Override
    public String getReaderName() {
        return DataxConstants.OSS_READER;
    }

    /**
     * 获取Writer插件名称
     * @return
     */
    @Override
    public String getWriterName() {
        return null;
    }

    @Override
    public Map<String, Object> buildReader(BaseDataxParam param) {
        OssDataxParam dataxParam = (OssDataxParam) param;

        // 构建
        Map<String, Object> readerObj = new HashMap<>(4);
        readerObj.put(DataxConstants.NAME, getReaderName());
        Map<String, Object> parameterObj = new HashMap<>(16);
        parameterObj.put(DataxConstants.OSS_ENDPOINT, dataxParam.getEndpoint());
        parameterObj.put(DataxConstants.OSS_ACCESSID, dataxParam.getAccessId());
        parameterObj.put(DataxConstants.OSS_ACCESS_KEY, dataxParam.getAccessKey());
        parameterObj.put(DataxConstants.OSS_BUCKET, dataxParam.getBucket());
        parameterObj.put(DataxConstants.OSS_FILE_TYPE, dataxParam.getFileType());
        parameterObj.put(DataxConstants.OSS_FIELD_DELIMITER, dataxParam.getFieldDelimiter());
        parameterObj.put(DataxConstants.OSS_OBJECT, dataxParam.getReaderPath());
        parameterObj.put(DataxConstants.OSS_COLUMN, dataxParam.getReaderColumn());
        parameterObj.put(DataxConstants.HDFS_ENCODING, DataxConstants.HDFS_UTF8);
        parameterObj.put(DataxConstants.HDFS_SKIP_HEADER, dataxParam.getSkipHeader());
        parameterObj.put(DataxConstants.HDFS_SKIP_LINES, dataxParam.getSkipLines());
        parameterObj.put(DataxConstants.HDFS_SHEET_TAB, dataxParam.getSheetTab());
        parameterObj.put(DataxConstants.HDFS_JSON_PATH, dataxParam.getJsonPath());
        parameterObj.put(DataxConstants.HDFS_QUOTATION, dataxParam.getQuotation());
        parameterObj.put(DataxConstants.HDFS_SINGLE_QUOTATION, dataxParam.getSingleQuotation());
        parameterObj.put(DataxConstants.HDFS_DOUBLE_QUOTATION, dataxParam.getDoubleQuotation());

        readerObj.put(DataxConstants.PARAMETER, parameterObj);
        return readerObj;
    }

    @Override
    public Map<String, Object> buildWriter(BaseDataxParam param) {
        return null;
    }

}
